package com.party.core.service.mall.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.mall.MallDataDetailReadDao;
import com.party.core.dao.write.mall.MallDataDetailWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.mall.MallDataDetail;
import com.party.core.service.mall.IMallDataDetailService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * @Description:
 * @Author: yangshoukun
 * @Date: 2018/5/23 15:22
 */
@Service
public class MallDataDetailService implements IMallDataDetailService {

    @Autowired
    private MallDataDetailReadDao mallDataDetailReadDao;

    @Autowired
    private MallDataDetailWriteDao mallDataDetailWriteDao;

    @Override
    public String insert(MallDataDetail mallDataDetail) {
        BaseModel.preInsert(mallDataDetail);
        boolean result = mallDataDetailWriteDao.insert(mallDataDetail);
        if(result){
            return mallDataDetail.getId();
        }
        return mallDataDetail.getId();
    }

    @Override
    public boolean update(MallDataDetail mallDataDetail) {
        mallDataDetail.setUpdateDate(new Date());
        return mallDataDetailWriteDao.update(mallDataDetail);
    }

    @Override
    public boolean deleteLogic(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return mallDataDetailWriteDao.deleteLogic(id);
    }

    @Override
    public boolean delete(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return mallDataDetailWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        return mallDataDetailWriteDao.batchDeleteLogic(ids);
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return mallDataDetailWriteDao.batchDelete(ids);
    }

    @Override
    public MallDataDetail get(String id) {
        return mallDataDetailReadDao.get(id);
    }

    @Override
    public List<MallDataDetail> listPage(MallDataDetail mallDataDetail, Page page) {
        return mallDataDetailReadDao.listPage(mallDataDetail, page);
    }

    @Override
    public List<MallDataDetail> list(MallDataDetail mallDataDetail) {
        return listPage(mallDataDetail, null);
    }

    @Override
    public List<MallDataDetail> batchList(Set<String> ids, MallDataDetail mallDataDetail, Page page) {
        return null;
    }

    @Override
    public MallDataDetail get(String memberId, Date createDate) {
        MallDataDetail mallDataDetail = new MallDataDetail();
        mallDataDetail.setMemberId(memberId);
        mallDataDetail.setCreateDate(createDate);
        return mallDataDetailReadDao.getByCreateDate(mallDataDetail);
    }
}
